package com.tz.platform.utils;

import java.util.Random;

import com.tz.platform.common.Constants;

/**
 * 密码管理
 * @version 1.0
 */
public class PasswordManage
{
	private String defaultPwd = Constants.DEFAULT_PASSWORD;
  private String pwdUseType = "default";
  private String pwdSecurityLevel = "mid";
  private String pwdSecurityHigh = "[0-9]+|[a-zA-Z]+";  //安全性弱的密码:只包含纯数字或字母
  private String pwdSecurityMid = "[0-9a-zA-Z]*([0-9]+[a-zA-Z]+|[a-zA-Z]+[0-9]+)[0-9a-zA-Z]*";   //安全性中的密码：含数字和字母的密码
  private String pwdSecurityLow = "[0-9a-zA-Z]*[-`=;',./~!@#$%^*()_+{}:?]*[-`=;',./~!@#$%^*()_+{}:?]+[0-9a-zA-Z]*[-`=;',./~!@#$%^*()_+{}:?]*";   //安全性强的密码：含数字、字母特殊字符的密码
  
  /** 
  * 生成随即密码 
  * @param pwd_len  //生成的密码的总长度
  * @return 密码的字符串 
  */ 
  public String getRandomPwd(int pwd_len) 
  { 
    final int maxNum = 36;                    // 35是因为数组是从0开始的，26个字母+10个数字 
    int i;                                    // 生成的随机数 
    int count = 0;                            // 生成的密码的长度 
    char[] str = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 
                   'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 
                   'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; 

    StringBuffer pwd = new StringBuffer(""); 
    Random r = new Random(); 
    while (count < pwd_len) 
    { 
      i = Math.abs(r.nextInt(maxNum));        // 生成随机数，取绝对值，防止生成负数,生成的数最大为36-1 
      if (i >= 0 && i < str.length) 
      { 
        pwd.append(str[i]); 
        count++;  
      }
    }
    return pwd.toString(); 
  }

  public String getDefaultPwd ( )
  {
    return defaultPwd;
  }
  public void setDefaultPwd ( String defaultPwd )
  {
    this.defaultPwd = defaultPwd;
  }
  public String getPwdUseType ( )
  {
    return pwdUseType;
  }
  public void setPwdUseType ( String pwdUseType )
  {
    this.pwdUseType = pwdUseType;
  }
  public String getPwdSecurityLevel ( )
  {
    return pwdSecurityLevel;
  }
  public void setPwdSecurityLevel ( String pwdSecurityLevel )
  {
    this.pwdSecurityLevel = pwdSecurityLevel;
  }
  public String getPwdSecurityHigh ( )
  {
    return pwdSecurityHigh;
  }
  public void setPwdSecurityHigh ( String pwdSecurityHigh )
  {
    this.pwdSecurityHigh = pwdSecurityHigh;
  }
  
  public String getPwdSecurityMid ( )
  {
    return pwdSecurityMid;
  }
  public void setPwdSecurityMid ( String pwdSecurityMid )
  {
    this.pwdSecurityMid = pwdSecurityMid;
  }
  public String getPwdSecurityLow ( )
  {
    return pwdSecurityLow;
  }
  public void setPwdSecurityLow ( String pwdSecurityLow )
  {
    this.pwdSecurityLow = pwdSecurityLow;
  }
  
}